package com.yiqi.liebang.feature.order.view.adapter;

import android.text.TextUtils;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.suozhang.framework.framework.AM;
import com.yiqi.liebang.R;
import com.yiqi.liebang.common.widget.RatingBar;
import com.yiqi.liebang.entity.bo.OrderBo;
import com.yiqi.liebang.entity.enums.OrderStautsHJ;
import com.yiqi.liebang.entity.enums.OrderStautsXY;

public class QuestionAdapter extends BaseQuickAdapter<OrderBo, BaseViewHolder> {
    private int mType;

    public QuestionAdapter(int mType) {
        super(R.layout.item_order_question);
        this.mType = mType;
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderBo item) {
        helper.setText(R.id.tv_order_question_content, item.getQuestionFormMap().getQuizcontent())
                .setText(R.id.tv_order_question_help, item.getQuestionFormMap().getUserAccountFormMap() == null ? "" : "帮助过" + item.getQuestionFormMap().getUserAccountFormMap().getHelpNum() + "人")
                .setText(R.id.tv_order_question_name, item.getQuestionFormMap().getUserAccountFormMap() == null ? "" : item.getQuestionFormMap().getUserAccountFormMap().getUserName() + "")
                .setText(R.id.tv_order_question_position, item.getQuestionFormMap().getUserAccountFormMap() == null ? "" :
                      (TextUtils.isEmpty(item.getQuestionFormMap().getUserAccountFormMap().getPosition())?"":item.getQuestionFormMap().getUserAccountFormMap().getPosition()))
                .setText(R.id.tv_order_question_prize, mType == 4 ? item.getPayPrice() + "" : item.getOrderPrice() + "")
                .setVisible(R.id.tv_order_question_time, item.getOrderStates()==1?true:false)
                .setText(R.id.tv_order_question_status, mType==4?OrderStautsHJ.getName(item.getOrderStates()): OrderStautsXY.getName(item.getOrderStates()))
                .setVisible(R.id.iv_user_position, item.getQuestionFormMap().getUserAccountFormMap() == null ? false : item.getQuestionFormMap().getUserAccountFormMap().getIsOccupation() == 1 ? true : false)
                .setVisible(R.id.tv_order_question_new, item.getReadStatus() == 0 ? true : false)
                .setText(R.id.tv_order_question_time,  getDatePoor(item.getQuestionFormMap().getEndTime(), System.currentTimeMillis()) )
        .addOnClickListener(R.id.iv_order_question_head)
        ;
        RatingBar ratingBar = helper.getView(R.id.star_order_question);
        ratingBar.setStar(item.getQuestionFormMap().getStartLevel());
        AM.image().bindToCircleObject(item.getQuestionFormMap().getUserAccountFormMap().getUserHead(), helper.getView(R.id.iv_order_question_head));
    }

    public static String getDatePoor(long endDate, long nowDate) {

        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        // long ns = 1000;
        // 获得两个时间的毫秒时间差异
        long diff = endDate - nowDate;
        // 计算差多少天
        long day = diff / nd;
        // 计算差多少小时
        long hour = diff % nd / nh;
        // 计算差多少分钟
        long min = diff % nd % nh / nm;
        // 计算差多少秒//输出结果
        // long sec = diff % nd % nh % nm / ns;
        return min>0?"剩余" +(day > 0 ? day + "天" : "") + (hour > 0 ? hour + "小时" : "") + min + "分钟问题失效":"已失效";
    }
}
